import java.lang.invoke.MethodHandle;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.MethodType;

/**
 * @author zxs
 * @since 2021/4/21
 */
public class DynamicDispatch {
    static class Human {
        void sayHello() {
            System.out.println("human say hello");
        }
    }

    static class Man extends Human {
        @Override
        void sayHello() {
            System.out.println("man say hello");
            try{
                MethodType mt = MethodType.methodType(void.class);
                MethodHandle mh = MethodHandles.lookup().findSpecial(Human.class, "sayHello", mt, getClass());
                mh.invoke(this);
            }catch(Throwable e){

            }

        }
    }


    public static void main(String[] args) {
       new Man().sayHello();

    }
}
